<template>
  <div class="addgooddialog">
    <el-dialog
      :title="dialog.title"
      :visible.sync="dialog.show"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :modal-append-to-body="false"
    >
      <div class="form">
        <el-form
          ref="form"
          :rules="form_rules"
          :model="formData"
          label-width="120px"
          style="margin: 10px; width: auto"
        >
          <el-form-item prop="name" label="道具名字:">
            <el-input type="name" v-model="formData.name"></el-input>
          </el-form-item>
          <el-form-item prop="info" label="描述:">
            <el-input type="info" v-model="formData.info"></el-input>
          </el-form-item>
          <el-form-item prop="level" label="等级:">
            <el-input type="level" v-model="formData.level"></el-input>
          </el-form-item>
          <el-form-item prop="rare_level" label="稀有度:">
            <el-input
              type="rare_level"
              v-model="formData.rare_level"
            ></el-input>
          </el-form-item>
          <el-form-item prop="price" label="商店固定价格:">
            <el-input type="price" v-model="formData.price"></el-input>
          </el-form-item>
          <el-form-item prop="is_sell" label="是否可以交易:">
            <el-input type="is_sell" v-model="formData.is_sell"></el-input>
          </el-form-item>
          <el-form-item prop="is_system_sell" label="是否可以交易:">
            <el-input
              type="is_system_sell"
              v-model="formData.is_system_sell"
            ></el-input>
          </el-form-item>
          <el-form-item prop="type" label="类型（0道具，1装备）:">
            <el-input type="type" v-model="formData.type"></el-input>
          </el-form-item>
          <el-form-item prop="use_type" label="使用类型:">
            <el-input type="use_type" v-model="formData.use_type"></el-input>
          </el-form-item>
          <el-form-item prop="goods_type" label="商品类型ObjID:">
            <el-select v-model="formData.goods_type" placeholder="商品类型">
              <el-option
                v-for="(formtype, index) in format_type_list"
                :key="index"
                :label="formtype.name"
                :value="formtype.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="skill" label="特技:">
            <el-input type="skill" v-model="formData.skill"></el-input>
          </el-form-item>
          <el-form-item prop="equipment" label="装备原始:">
            <el-input type="equipment" v-model="formData.equipment"></el-input>
          </el-form-item>
          <el-form-item prop="status" label="状态:">
            <el-input type="status" v-model="formData.status"></el-input>
          </el-form-item>
          <el-form-item class="text_right">
            <el-button @click="onSubmit('form')">提交</el-button>
            <el-button @click="dialog.show = false">取消</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "addgooddialog",
  data() {
    return {
      form_rules: {
        goods_type: [
          { required: true, message: "物品类型不能为空！", trigger: "blur" },
        ],
      },
    };
  },
  props: {
    dialog: Object,
    formData: Object,
    format_type_list: Array,
  },
  created() {
  },
  methods: {
    onSubmit(form) {
      this.$refs[form].validate((valid) => {
        if (valid) {
          const url =
            this.dialog.option == "add"
              ? "addgood"
              : `edit/${this.formData.id}`;
          this.$axios.post(`/api/goods/${url}`, this.formData).then((res) => {
            // 添加成功
            this.$message({
              message: "数据添加成功",
              type: "success",
            });
          });
          // 隐藏dialog
          this.dialog.show = false;
          this.$emit("update");
          location.reload(true);
        }
      });
    },
  },
};
</script>

<style scoped>
</style>

